package com.loop.practice;

public class InClassPractice {
    public static void main(String[] args) {
        System.out.println(reverseStr("abc"));
        int[] a={1,2,3};
        System.out.println(toStringArr(a));
    }

    /**
     * 接受字符串，返还其反转后的字符串
     * @param str
     * @return
     */
    public static String reverseStr(String str){
        if (str==null||str.length()<2){
            return str;
        }
        return new StringBuilder(str).reverse().toString();
    }

    /**
     * 将数组{1,2,3}变成[1,2,3]
     * @param nums
     * @return
     */
    public static String toStringArr(int[] nums){
        if (nums==null){
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            stringBuilder.append(nums[i]).append(",");
        }
        stringBuilder.insert(0,"[");
        stringBuilder.replace(stringBuilder.length()-1,stringBuilder.length(),"]");
        return stringBuilder.toString();
    }
}
